﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SimpleTaskSystem;
using UnityEngine.UI;

public class ExampleGameManager : MonoBehaviour {
    public Text taskText,operationText;
    public TaskManager taskManager;

    private void Awake()
    {
        taskManager = FindObjectOfType<TaskManager>();
        taskManager.onStart += delegate () 
        {
            UpdateTaskInfo(null);
        };
    }
    // Use this for initialization
    void Start () {
        
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void StartGame()
    {
        taskManager.StartTask();
    }

    void UpdateTaskInfo(Operation o)
    {
        if (!taskManager.isOver)
        {
            if (o != null)
            {
                o.onCompleted -= UpdateTaskInfo;
            }
            Task t = taskManager.GetCurrentTask();
            Operation o2 = t == null ? null : t.GetCurrentOperation();
            if (o2 != null)
            {
                o2.onCompleted += UpdateTaskInfo;
            }
            SetText(t == null ? "暂无任务" : t.taskName, o2 == null ? "暂无操作" : o2.description);
        }
        else
        {
            SetText("任务已完成", "任务已完成");
        }
    }

    void SetText(string taskName,string opd)
    {
        taskText.text = "任务名："+ taskName;
        operationText.text = "操作："+opd;
    }
}
